home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / pd / utilities / tinymeter / source / tinymeter_main / misc.c < prev    next >
C/C++ Source or Header  |  1996-05-20  |  5KB  |  184 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/imageclass.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/cghooks.h>
  12. #include <intuition/icclass.h>
  13. #include <intuition/classes.h>
  14. #include <intuition/sghooks.h>
  15. #include <intuition/screens.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <utility/tagitem.h>
  20. #include <utility/hooks.h>
  21. #include <string.h>
  22. #include <datatypes/datatypesclass.h>
  23. #include <datatypes/datatypes.h>
  24. #include <datatypes/pictureclass.h>
  25. #include "gaugeclass.h"
  26. #include "tinymeter.h"
  27.  
  28. /*
  29.     Perhaps the next two functions will be useful for some of you... 8))
  30.     I searched a long time for something similar, finally I did them myself.
  31.     Please leave me a mail, if you are using them...
  32. */
  33. /*
  34. BltTLine(struct BitMap *src, UWORD s_x, UWORD s_y, struct RastPort *dest, UWORD d_x, UWORD d_y, UWORD h, UBYTE t_col, UBYTE *mask)
  35. {
  36.     ULONG           i,k,pos,skip;
  37.     UBYTE           *s1,*s2,*s3;
  38.     BOOL            firstrun=FALSE;
  39.     if( mask)
  40.     {
  41.     pos =((s_x+7)>>3);
  42.     skip=src->BytesPerRow;
  43.  
  44.     for(i=0;i<src->Depth;i++)
  45.     {
  46.         s1 = (UBYTE *)mask+(UBYTE *)pos;
  47.         s2 = (UBYTE *)src->Planes[i]+(UBYTE *)pos;
  48.         if(firstrun)
  49.         {
  50.         if((1<<i)&t_col) for(k=0;k<src->Rows;k++,s1+=skip,s2+=skip) *s1&=         *s2;
  51.         else             for(k=0;k<src->Rows;k++,s1+=skip,s2+=skip) *s1&=       ~(*s2);
  52.         }
  53.         else
  54.         {
  55.         firstrun=TRUE;
  56.         if((1<<i)&t_col) for(k=0;k<src->Rows;k++,s1+=skip,s2+=skip) *s1=(0xFF)&  (*s2);
  57.         else             for(k=0;k<src->Rows;k++,s1+=skip,s2+=skip) *s1=(0xFF)&(~(*s2));
  58.         }
  59.     }
  60.     BltMaskBitMapRastPort(src,s_x,s_y,dest,d_x,d_y,1,h,0xb0,mask);
  61.     }
  62. }
  63.  
  64. */
  65. BltT(struct BitMap *src, UWORD s_x, UWORD s_y, struct RastPort *dest, UWORD d_x, UWORD d_y, UWORD w, UWORD h, UBYTE t_col, UBYTE *mask)
  66. {
  67.     ULONG           i,k;
  68.     UBYTE           *s1,*s2,*s3;
  69.     BOOL            allocated=FALSE,firstrun=FALSE;
  70.     k = src->BytesPerRow*src->Rows;
  71.     if(!mask) { mask=(UBYTE *)AllocVec(k,MEMF_CHIP); allocated=TRUE; }
  72.     if( mask)
  73.     {
  74.     s3 = mask+k+1;
  75.     for(i=0;i<src->Depth;i++)
  76.     {
  77.         s1 = (UBYTE *)mask;
  78.         s2 = (UBYTE *)src->Planes[i];
  79.         if(firstrun)
  80.         {
  81.         if((1<<i)&t_col) for(;s1<s3;s1++) *s1&=         *(s2++);
  82.         else             for(;s1<s3;s1++) *s1&=       ~(*(s2++));
  83.         }
  84.         else
  85.         {
  86.         firstrun=TRUE;
  87.         if((1<<i)&t_col) for(;s1<s3;s1++) *s1=(0xFF)&  (*(s2++));
  88.         else             for(;s1<s3;s1++) *s1=(0xFF)&(~(*(s2++)));
  89.         }
  90.     }
  91.     BltMaskBitMapRastPort(src,s_x,s_y,dest,d_x,d_y,w,h,0xb0,mask);
  92.     if(allocated) FreeVec(mask);
  93.     }
  94. }
  95.  
  96. DrawDTObject(Object *src, UWORD s_x, UWORD s_y, struct RastPort *dest, UWORD d_x, UWORD d_y, WORD w, WORD h, BOOL really)
  97. {
  98.     UBYTE               *ColorTable;
  99.     struct BitMapHeader *bmhd;
  100.     struct BitMap       *bm;
  101.     GetDTAttrs(src,PDTA_BitMapHeader,&bmhd,PDTA_DestBitMap,&bm,PDTA_ColorTable,&ColorTable,TAG_DONE);
  102.     if(w=-1)w=bmhd->bmh_Width;
  103.     if(h=-1)h=bmhd->bmh_Height;
  104.     if (!bm) GetDTAttrs(src,PDTA_BitMap,&bm,TAG_DONE);
  105.     if((bmhd->bmh_Masking==mskHasTransparentColor)&&(ColorTable)&&(really!=FALSE))
  106.     BltT(bm,s_x,s_y,dest,d_x,d_y,w,h,ColorTable[bmhd->bmh_Transparent],NULL);
  107.     else
  108.     BltBitMapRastPort(bm,s_x,s_y,dest,d_x,d_y,w,h,0xc0);
  109. }
  110.  
  111. int my_strlen(char s[])
  112. {
  113.    int i=0;
  114.    while (s[i]!='\0')++i;
  115.    return(i);
  116. }
  117.  
  118. UBYTE long_2_string_with_thousand(ULONG num, char output[], char point, BOOL negative)
  119. {
  120.     char             output_private[16];
  121.     char             n      = 0;
  122.     char             n_1    = 0;
  123.     if(negative)output[n_1++]='-';
  124.     sprintf(output_private,"%12ld",num);
  125.     while(output_private[n]==0x20)n++;
  126.     for(;(output_private[n]!=0)&(output_private[n]!=0x20);n++)
  127.     {
  128.     output[n_1++]=output_private[n];
  129.     if((n==2)||(n==5)||(n==8)) output[n_1++]=(char)point;
  130.     }
  131.     output[n_1]=0;
  132.     return(n_1);
  133. }
  134.  
  135. void draw_border_new( struct RastPort *rp,ULONG x, ULONG y, ULONG width, ULONG height, int b_col1, int b_col2 )
  136. {
  137.     width--;height--;
  138.     SetAPen(rp,b_col1);
  139.     RectFill(rp,x,y,x,y+height);
  140.     RectFill(rp,x,y,x+width,y);
  141.     SetAPen(rp,b_col2);
  142.     RectFill(rp,x+width,y,x+width,y+height);
  143.     RectFill(rp,x,y+height,x+width,y+height);
  144. }
  145.  
  146. my_RectFill(struct RastPort *rp,WORD x,WORD y,WORD width,WORD height)
  147. {
  148.     if(((x+width)>1)&&((y+height)>1)) RectFill(rp,x,y,x+width-1,y+height-1);
  149. }
  150.  
  151. my_Blit(struct RastPort *src, WORD topx, WORD topy, struct RastPort *dest, WORD dtopx, WORD dtopy, WORD width, WORD height)
  152. {
  153.     ClipBlit(src,topx,topy,dest,dtopx,dtopy,width,height,0xC0);
  154. }
  155.  
  156. FreePenNew( struct Screen *scr, struct GAU_Color *col,ULONG number, ULONG *Pens)
  157. {
  158.     if(!col->pen) ReleasePen(scr->ViewPort.ColorMap,Pens[number]);
  159. }
  160.  
  161. UWORD obtainPen( struct Screen *src, struct GAU_Color *scr)
  162. {
  163.     return(scr->pen ? scr->red : ObtainBestPenA(src->ViewPort.ColorMap, scr->red, scr->green, scr->blue, 0L) );
  164. }
  165.  
  166. GetPenNew(struct Screen *scr,struct GAU_Color *col,ULONG number, BOOL *PorC, ULONG *Pens)
  167. {
  168.     PorC[number]= col->pen ? FALSE    : TRUE;
  169.     Pens[number]= obtainPen(scr,col);
  170. }
  171.  
  172. struct TextFont *OpenTopaz()
  173. {
  174.     static struct TextAttr topaz_font =
  175.     {
  176.     "topaz.font",
  177.     8,
  178.     0,
  179.     FPF_ROMFONT,
  180.     };
  181.     return((struct TextFont *)OpenFont( &topaz_font));
  182. }
  183.  
  184.